import { getNetworkAccountInfoByPhone } from '@/api/network'
import { ref } from 'vue'

export default () => {
  // 获取账号信息加载
  const getAccountInfoLoading = ref(false)

  // 账号信息
  const accountInfoByPhone = ref<NetworkAccountInfoByPhone>({
    avatar: '',
    id: '',
    name: '',
    networkEmpId: '',
    networkEmpRelationId: '',
    networkId: '',
    nickname: '',
    phone: '',
  })

  /**
   * 获取账号信息
   * @param {string} phone - 手机号
   */
  const getAccountInfo = async (phone: string, networkId: string) => {
    getAccountInfoLoading.value = true
    const res = await getNetworkAccountInfoByPhone(phone, networkId)
    getAccountInfoLoading.value = false
    accountInfoByPhone.value = res.data.data.row
  }

  return {
    accountInfoByPhone,
    getAccountInfoLoading,
    getAccountInfo,
  }
}
